package vn.gq.udv.db.items;

import org.json.JSONException;
import org.json.JSONObject;
import android.os.Parcel;
import android.os.Parcelable;

public class Category implements Parcelable {
	private int catId;
	private String catName;
	private int root;
	
	
	public Category() {
	}
	
	public Category(String json) throws JSONException {
		JSONObject ob = new JSONObject(json);
		catId = ob.getInt("catId");
		catName = ob.getString("catName");
		root = ob.getInt("root");
	}
	
	public Category(Parcel source) {
		catId = source.readInt();
		catName = source.readString();
		root = source.readInt();
	}
	
	public String getCatName() {
		return catName;
	}
	
	public void setCatName(String catName) {
		this.catName = catName;
	}
	
	public int getRoot() {
		return root;
	}
	
	public void setRoot(int root) {
		this.root = root;
	}
	
	public int getCatId() {
		return catId;
	}
	
	public void setCatId(int catId) {
		this.catId = catId;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(catId);
		dest.writeString(catName);
		dest.writeInt(root);
	}
	
	public static final Parcelable.Creator<Category> CREATOR = new Parcelable.Creator<Category>() {
		
		@Override
		public Category[] newArray(int size) {
			return new Category[size];
		}
		
		@Override
		public Category createFromParcel(Parcel source) {
			return new Category(source);
		}
	};
	
	public JSONObject toJSONObject() {
		JSONObject ob = new JSONObject();
		try {
			ob.put("catId", catId);
			ob.put("catName", catName);
			ob.put("root", root);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return ob;
	}
}
